package com.hoshiicloud.vericenter.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hoshiicloud.vericenter.entity.SysMessages;
import com.hoshiicloud.vericenter.entity.param.SysMessagesQueryParam;
import com.hoshiicloud.vericenter.entity.vo.SysMessagesDetailVO;
import com.hoshiicloud.vericenter.entity.vo.SysMessagesVO;
import com.hoshiicloud.vericenter.result.Response;
import com.hoshiicloud.vericenter.service.ISysMessagesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import javax.validation.Valid;

/**
 * 短信接口
 * TODO 改为多租户模式,租户需提供相应的配置参数
 */
@Api(value = "短信查询接口",tags = "短信查询接口")
@RestController
@RequestMapping("/sms")
public class SysMessagesController {

    @Autowired
    private ISysMessagesService sysMessagesService;

    @ApiOperation(value = "获取详情")
    @RequestMapping(value = "/getDetail", method = RequestMethod.GET)
    public Response<SysMessagesDetailVO> getPermissionDetail(@RequestParam String id) {
        if (StringUtils.isBlank(id)) {
            return Response.failed("id不能为空");
        }
        return sysMessagesService.getDetail(id);
    }
    @ApiOperation("分页查询短信")
    @RequestMapping(value = "/getPage", method = RequestMethod.GET)
    public Response<SysMessagesVO> getPermissionPage(@Valid SysMessagesQueryParam param,
                                                     BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return Response.failed("参数有误:" + bindingResult.getFieldError().toString());
        }
        QueryWrapper<SysMessages> queryWrapper = param.convertToQueryWrapper();

        IPage<SysMessages> page = new Page<>(Long.parseLong(param.getPageNumber()),
                Long.parseLong(param.getPageSize()));

        return sysMessagesService.getPage(page, queryWrapper);
    }
}
